package com.fyzk.activity.lottery.gaopin;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.app.AppToast;
import com.fyzk.activity.down_numhistory.NumHistoryPrizeView;
import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.activity.lottery.shuzicai.LotteryBaseActivity;
import com.fyzk.activity.lottery.shuzicai.SelectBallView;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallClickListener;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallItemClickLitener;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupItemBean;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupwindow;
import com.fyzk.activity.myview.BallPopFrameLayout;
import com.fyzk.activity.myview.BallScrollView;
import com.fyzk.activity.myview.DrawBallFrameLayout;
import com.fyzk.activity.myview.WeiZhi;
import com.fyzk.bean.PrizeHistoryItem;
import com.fyzk.betzhushu.ZhuShuFactory;
import com.tyjc.lottery.R;
import com.fyzk.random.KLSFRandom;
import com.fyzk.random.RandomFactory;
import com.fyzk.utils.HelpUrlConstants;
import com.fyzk.utils.LogUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.view.BottomView;
import com.fyzk.view.BottomView.onBottomClickListener;
import com.fyzk.view.TopTitleView;
import com.fyzk.view.ViewCallBack;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;


@ContentView(R.layout.ac_klsf)
public class KLSFActivity extends LotteryBaseActivity implements KLPKPopupwindow.KLPKPopuponItemListener,
        BallItemClickLitener, BallClickListener, onBottomClickListener {

    private TopTitleView topView;

    private int[] popup_itemsId = {R.string.klsf_selonenum, R.string.klsf_selonered, R.string
            .klsf_seltwo, R.string.klsf_selthree, R.string.klsf_selfour, R.string.klsf_selfive,
            R.string.klsf_twostraight, R.string.klsf_twogroup, R.string.klsf_seltwo_duplex, R
            .string.klsf_selthree_duplex, R.string.klsf_selfour_duplex, R.string
            .klsf_selfive_duplex, R.string.klsf_twogroup_duplex};

    private String[] popup_itemsStr2 = {"奖金","奖金","奖金","奖金","奖金","奖金",
            "奖金","奖金","","","","",""};
    private String[] popup_itemsStr3 = {"25米","5米","8米","24米","80米","320米",
            "62米","31米","","","","",""};
    protected List<KLPKPopupItemBean> popup_items = new ArrayList<>();
    protected KLPKPopupwindow top_popup;

//    private String[] popup_items = new String[popup_itemsId.length];

    private final int KLSF_SELONENUM = 0x0;// 选一数投
    private final int KLSF_SELONERED = 0x1;// 选一红投
    private final int KLSF_SELTWO = 0x2;// 任选二
    private final int KLSF_SELTHREE = 0x3;// 任选三
    private final int KLSF_SELFOUR = 0x4;// 任选四
    private final int KLSF_SELFIVE = 0x5;// 任选五
    private final int KLSF_TWOSTRAIGHT = 0x6;// 选二连直
    private final int KLSF_TWOGROUP = 0x7;// 选二连组
    private final int KLSF_SELTWO_DUPLEX = 0x8;// 任选二胆拖
    private final int KLSF_SELTHREE_DUPLEX = 0x9;// 任选三胆拖
    private final int KLSF_SELFOUR_DUPLEX = 0xa;// 任选四胆拖
    private final int KLSF_SELFIVE_DUPLEX = 0xb;// 任选五胆拖
    private final int KLSF_TWOGROUP_DUPLEX = 0xc;// 二连组胆拖

    private SelectBallView ballView_one;
    private SelectBallView ballView_two;


    @ViewInject(R.id.shake_random_ll)
    private LinearLayout shake_random_ll;


    private TextView txt_title1;
    private TextView txt_title2;

    private TextView txt_alert1;
    private TextView txt_alert2;

//    private int ball_count = 20;

    private List<BallInfo> balls_firstLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_twoLine = new ArrayList<BallInfo>();

    private LinearLayout mLl_one;
    private LinearLayout mLl_two;

    // 底部
    private BottomView bottomView;
    private BallScrollView ball_scroll;
    private DrawBallFrameLayout ball_linear;
    private BallPopFrameLayout moveQiu;


    int ballcount = 20;
    int start = 1;

    private TextView prize_tishi_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        shake_random_ll.setOnClickListener(this);
        init();
        top_popup.setCheckItem(popupId);
        topView.setCenterText(popup_items.get(popupId).str1);
        ViewCallBack.getInstance().AttachCountDownObj(this);
        popupClickItem(popupId);
        ballClick();
    }

    @Override
    public TopTitleView getTopView() {
        return topView;
    }

    protected String[] getMenuItems() {
        return new String[]{"开奖公告", "玩法介绍","投注查询"};
    }

    @Override
    protected void init() {
        // TODO Auto-generated method stub
        super.init();
        prize_tishi_tv = (TextView) findViewById(R.id.prize_tishi_tv);
        for (int i = 0; i < popup_itemsId.length; i++) {

            KLPKPopupItemBean itemBean = new KLPKPopupItemBean();
            itemBean.str1 = getString(popup_itemsId[i]);
            itemBean.str2 = popup_itemsStr2[i];
            itemBean.str3 = popup_itemsStr3[i];
            popup_items.add(itemBean);
        }
        top_popup = new KLPKPopupwindow(this, AbsListView.LayoutParams.MATCH_PARENT, AbsListView
                .LayoutParams.WRAP_CONTENT,
                popup_items, 8);
        top_popup.setHm_PopupOnItemListener(this);

        topView = (TopTitleView) findViewById(R.id.ssc_topTitle);
        topView.setOnTitleClickListener(this);
        topView.setJianTouVisible(View.VISIBLE);
        topView.setRightImg(R.drawable.downmenu_icon);
        topView.setRight2Visible(View.VISIBLE);
        topView.getRightImg2().setImageDrawable(getResources().getDrawable(R.drawable
                .icon_refresh));
        topView.setCenterText(popup_items.get(0).str1);

        ll_history = (LinearLayout) findViewById(R.id.ssc_ball_history);
        ball_linear = (DrawBallFrameLayout) findViewById(R.id.ssc_drawball_framelayout);
        ball_scroll = (BallScrollView) findViewById(R.id.ssc_ballscroll);
        moveQiu = (BallPopFrameLayout) findViewById(R.id.ssc_fl_moveqiu);

        ball_linear.setScr(ball_scroll);
        ball_linear.setFl_moveqiu(moveQiu);
        ball_linear.setUpOrDownListener(this);

        ballView_one = (SelectBallView) findViewById(R.id.ssc_ballview_first);
        ballView_two = (SelectBallView) findViewById(R.id.ssc_ballview_two);

        txt_title1 = (TextView) findViewById(R.id.ssc_title_1);
        txt_title2 = (TextView) findViewById(R.id.ssc_title_2);

        txt_alert1 = (TextView) findViewById(R.id.ssc_alert_1);
        txt_alert2 = (TextView) findViewById(R.id.ssc_alert_2);

        TouZhuHelper.getInstance().setBallClickListener(this);

        TouZhuHelper.getInstance().setBallItemClickLitener(this);
        mLl_one = (LinearLayout) findViewById(R.id.linear_ssc_one);
        mLl_two = (LinearLayout) findViewById(R.id.linear_ssc_two);
        bottomView = (BottomView) findViewById(R.id.ssc_bottom);
        bottomView.setRightText("确定");
        bottomView.setLeftText("清除");
        bottomView.setonBottomClickListener(this);
        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");
        showSelOneNum();

    }

    @Override
    protected void initArrayInfos() {
        if (arr_infos.size() > 0) {
            switch (popupId) {
                case KLSF_SELONENUM://选一数投
                case KLSF_SELONERED:// 选一红投
                case KLSF_SELTWO:// 任选二
                case KLSF_SELTHREE:// 任选三
                case KLSF_SELFOUR:// 任选四
                case KLSF_SELFIVE:// 任选五
                case KLSF_TWOGROUP:// 二连组
                    balls_firstLine = arr_infos.get(0);
                    ballView_one.setBallInfoList(balls_firstLine);
                    break;
                case KLSF_TWOSTRAIGHT:// 二连直
                    balls_firstLine = arr_infos.get(0);
                    balls_twoLine = arr_infos.get(1);
                    ballView_one.setBallInfoList(balls_firstLine);
                    ballView_two.setBallInfoList(balls_twoLine);
                    break;
                case KLSF_SELTWO_DUPLEX:// 任选二胆拖
                case KLSF_SELTHREE_DUPLEX:// 任选三胆拖
                case KLSF_SELFOUR_DUPLEX:// 任选四胆拖
                case KLSF_SELFIVE_DUPLEX:// 任选五胆拖
                case KLSF_TWOGROUP_DUPLEX:// 二连组胆拖
                    balls_firstLine = arr_infos.get(0);
                    balls_twoLine = arr_infos.get(1);
                    ballView_one.setBallInfoList(balls_firstLine);
                    ballView_two.setBallInfoList(balls_twoLine);
                    break;

            }
        }
    }


    private void showSelOneNum() {
        prize_tishi_tv.setText(R.string.klsf_prize_x1s);
        arr_infos.clear();
        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(18);
        ballcount = 18;
        start = 1;
        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);
        shake_random_ll.setVisibility(View.VISIBLE);
    }

    private void showSelOneRed() {
        prize_tishi_tv.setText(R.string.klsf_prize_x1h);
        arr_infos.clear();
        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(1);
        ballcount = 2;
        start = 19;
        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);
        shake_random_ll.setVisibility(View.VISIBLE);
    }

    private void showSelTwo() {
        prize_tishi_tv.setText(R.string.klsf_prize_r2);
        arr_infos.clear();
        ballcount = 20;
        start = 1;
        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(ballcount);
        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);
        shake_random_ll.setVisibility(View.VISIBLE);
    }


    private void showSelThree() {
        prize_tishi_tv.setText(R.string.klsf_prize_r3);
        arr_infos.clear();
        ballcount = 20;
        start = 1;
        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);
        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(ballcount);
        shake_random_ll.setVisibility(View.VISIBLE);
    }

    private void showSelFour() {
        prize_tishi_tv.setText(R.string.klsf_prize_r4);
        arr_infos.clear();
        ballcount = 20;
        start = 1;
        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);
        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(ballcount);
        shake_random_ll.setVisibility(View.VISIBLE);
    }

    private void showSelFive() {
        prize_tishi_tv.setText(R.string.klsf_prize_r5);
        arr_infos.clear();

        ballcount = 20;
        start = 1;

        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);

        txt_title1.setText(R.string.selectNum);
        txt_alert1.setText("");
        mLl_one.setVisibility(View.VISIBLE);
        ballView_one.setSelect_max(ballcount);

        shake_random_ll.setVisibility(View.VISIBLE);

    }

    private void showSelTwoStraight() {
        prize_tishi_tv.setText(R.string.klsf_prize_x2l_zhi);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.VISIBLE);
        txt_title1.setText("前位");
        txt_title2.setText("后位");
        txt_alert1.setText("");
        txt_alert2.setText("");

        ballcount = 20;
        start = 1;

        arr_infos.clear();
        initBallList(balls_firstLine, ballcount, start, true);
        initBallList(balls_twoLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        arr_infos.add(balls_twoLine);
        ballView_one.setBallInfoList(balls_firstLine);
        ballView_two.setBallInfoList(balls_twoLine);
        ballView_one.setGuanLian_view(ballView_two);
        ballView_two.setGuanLian_view(ballView_one);
        ballView_one.setSelect_max(ballcount);
//        ballView_two.setSelect_max(1);
        shake_random_ll.setVisibility(View.VISIBLE);

    }

    private void showSelTwoGroup() {
        prize_tishi_tv.setText(R.string.klsf_prize_x2l_zu);
        arr_infos.clear();

        ballcount = 20;
        start = 1;

        txt_title1.setText(R.string.selectNum);

        txt_alert1.setText("");

        initBallList(balls_firstLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        ballView_one.setSelect_max(20);
        ballView_one.setBallInfoList(balls_firstLine);
        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.GONE);

        txt_title1.setText(R.string.selectNum);
        shake_random_ll.setVisibility(View.VISIBLE);

    }

    private void showSelDuplex(int maxDan) {

        mLl_one.setVisibility(View.VISIBLE);
        mLl_two.setVisibility(View.VISIBLE);


        txt_title1.setText(R.string.dannum);
        switch (maxDan) {
            case 1:
                if (popupId == 12) {    // 选2连组胆拖
                    prize_tishi_tv.setText(R.string.klsf_prize_x2l_zu_dan);
                } else {
                    prize_tishi_tv.setText(R.string.klsf_prize_r2_dan);
                }
                txt_alert1.setText(R.string.klsf_tishi_rx2_dan);
                break;
            case 2:
                prize_tishi_tv.setText(R.string.klsf_prize_r3_dan);
                txt_alert1.setText(R.string.klsf_tishi_rx3_dan);
                break;
            case 3:
                prize_tishi_tv.setText(R.string.klsf_prize_r4_dan);
                txt_alert1.setText(R.string.klsf_tishi_rx4_dan);
                break;
            case 4:
                prize_tishi_tv.setText(R.string.klsf_prize_r5_dan);
                txt_alert1.setText(R.string.klsf_tishi_rx5_dan);
                break;
        }
//        txt_alert1.setText(R.string.klsf_tishi_rx3_dan);
        txt_title2.setText(R.string.tuonum);
        txt_alert2.setText(R.string.klsf_tishi_tuo);
        arr_infos.clear();

        ballcount = 20;
        start = 1;

        initBallList(balls_firstLine, ballcount, start, true);
        initBallList(balls_twoLine, ballcount, start, true);
        arr_infos.add(balls_firstLine);
        arr_infos.add(balls_twoLine);
        ballView_one.setSelect_max(maxDan);
        ballView_one.setBallInfoList(balls_firstLine);
        ballView_two.setBallInfoList(balls_twoLine);
        ballView_one.setGuanLian_view(ballView_two);
        ballView_two.setGuanLian_view(ballView_one);

        shake_random_ll.setVisibility(View.GONE);
    }


    @Override
    public void onLeftClick() {
        // TODO Auto-generated method stub
        finish();
    }

    @Override
    public void onCenterClick() {
        // TODO Auto-generated method stub
        top_popup.showPopupWindow(topView);
    }

    @Override
    public void onRightClick() {
        // TODO Auto-generated method stub
        toHelp();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.shake_random_ll:
                randomBallNum();
                break;
        }
    }

    @Override
    public boolean touZhu() {
        // TODO Auto-generated method stub
        long zhuShu = getZhushu();
        if (zhuShu > 0) {
            int lotteryId = wanFaId;
            switch (wanFaId) {
                case LotteryIDUtils.KLSF_LOTTERY_RENER_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_RENER_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_RENSAN_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_RENSAN_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_RENSI_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_RENSI_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_RENWU_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_RENWU_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT:
                    lotteryId = LotteryIDUtils.KLSF_LOTTERY_XUANYI_HONG_FU_ID_INT;
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_FU_ID_INT;
                    }
                    break;
                case LotteryIDUtils.KLSF_LOTTERY_RENER_TOWED_ID_INT:
                case LotteryIDUtils.KLSF_LOTTERY_RENSAN_TOWED_ID_INT:
                case LotteryIDUtils.KLSF_LOTTERY_RENSI_TOWED_ID_INT:
                case LotteryIDUtils.KLSF_LOTTERY_RENWU_TOWED_ID_INT:
                case LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_TOWED_ID_INT:
                    if (zhuShu < 2) {
                        AppToast.getToast().show("胆拖至少选择2注");
                        return true;
                    } else {
                        break;
                    }
            }

            touZhu1(lotteryId, zhuShu);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void clear() {
        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");

        initBallList(balls_firstLine, ballcount, start, true);
        initBallList(balls_twoLine, ballcount, start, true);

        ballView_one.setSelect_count(0);
        ballView_two.setSelect_count(0);

        ballView_one.invalidate();
        ballView_two.invalidate();
    }

    @Override
    public int getLotteryId() {
        // TODO Auto-generated method stub
        return LotteryIDUtils.KLSF_LOTTERY_ID_INT;
    }

    private int curPostion;
//


    @Override
    protected void popupClickItem(int postion) {
        // TODO Auto-generated method stub
        this.curPostion = postion;
        popupId = postion;
        top_popup.setCheckItem(popupId);
        topView.setCenterText(popup_items.get(popupId).str1);
        switch (postion) {
            case KLSF_SELONENUM://选一数投
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_XUANYI_SHU_DAN_ID_INT;
                showSelOneNum();
                break;
            case KLSF_SELONERED:// 选一红投
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_XUANYI_HONG_DAN_ID_INT;
                showSelOneRed();
                break;
            case KLSF_SELTWO:// 任选二
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENER_DAN_ID_INT;
                showSelTwo();
                break;
            case KLSF_SELTHREE:// 任选三
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENSAN_DAN_ID_INT;
                showSelThree();
                break;
            case KLSF_SELFOUR:// 任选四
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENSI_DAN_ID_INT;
                showSelFour();
                break;
            case KLSF_SELFIVE:// 任选五
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENWU_DAN_ID_INT;
                txt_title1.setText(R.string.text_least_5);
                showSelFive();
                break;
            case KLSF_TWOSTRAIGHT:// 二连直
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZHI_DAN_ID_INT;
                showSelTwoStraight();
                break;
            case KLSF_TWOGROUP:// 二连组
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_DAN_ID_INT;
                showSelTwoGroup();
                break;
            case KLSF_SELTWO_DUPLEX:// 任选二胆拖
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENER_TOWED_ID_INT;
                showSelDuplex(1);
                break;
            case KLSF_SELTHREE_DUPLEX:// 任选三胆拖
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENSAN_TOWED_ID_INT;
                showSelDuplex(2);
                break;
            case KLSF_SELFOUR_DUPLEX:// 任选四胆拖
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENSI_TOWED_ID_INT;
                showSelDuplex(3);
                break;
            case KLSF_SELFIVE_DUPLEX:// 任选五胆拖
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_RENWU_TOWED_ID_INT;
                showSelDuplex(4);
                break;
            case KLSF_TWOGROUP_DUPLEX:// 二连组胆拖
                wanFaId = LotteryIDUtils.KLSF_LOTTERY_XUANER_LIANZU_TOWED_ID_INT;
                showSelDuplex(1);
                break;

        }
        addMissValue();
    }


    private LinearLayout ll_history;

    @Override
    protected void addHistoryView(ArrayList<PrizeHistoryItem> historyItems, boolean isWaitting) {
        // TODO Auto-generated method stub
        ll_history.removeAllViews();
        ll_history.addView(new NumHistoryPrizeView(getContext(), historyItems).getView());
    }

    @Override
    public void randomBallNum() {
        clear();
        switch (curPostion) {
            case KLSF_SELONENUM:// 选一数投

            {
                int first = ((KLSFRandom) (RandomFactory.getRandom(getLotteryId())))
                        .randomShu1(1)[0];
                balls_firstLine.get(first).setSelected(true);
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case KLSF_SELONERED:// 选一红投
            {
                int first = ((KLSFRandom) (RandomFactory.getRandom(getLotteryId())))
                        .randomDanHong(1)[0];
                balls_firstLine.get(first).setSelected(true);
                ballView_one.invalidate();
                ballClick();
            }
            break;

            case KLSF_SELTWO:// 任选二
            {
                int[] randoms = RandomFactory.getRandom(getLotteryId()).randomDanHang(2);
                balls_firstLine.get(randoms[0]).setSelected(true);
                balls_firstLine.get(randoms[1]).setSelected(true);
                ballView_one.invalidate();
                ballClick();
            }
            break;

            case KLSF_SELTHREE:// 任选三
            {
                int[] randoms = RandomFactory.getRandom(getLotteryId()).randomDanHang(3);
                balls_firstLine.get(randoms[0]).setSelected(true);
                balls_firstLine.get(randoms[1]).setSelected(true);
                balls_firstLine.get(randoms[2]).setSelected(true);
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case KLSF_SELFOUR:// 任选四
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(4);
                for (int i = 0; i < first.length; i++) {
                    balls_firstLine.get(first[i]).setSelected(true);
                }
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case KLSF_SELFIVE:// 任选五
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(5);
                for (int i = 0; i < first.length; i++) {
                    balls_firstLine.get(first[i]).setSelected(true);
                }
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case KLSF_TWOSTRAIGHT:// 选二连直
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(2);
                balls_firstLine.get(first[0]).setSelected(true);
                balls_twoLine.get(first[1]).setSelected(true);
                ballView_one.invalidate();
                ballView_two.invalidate();
                ballClick();
            }
            break;

            case KLSF_TWOGROUP:// 选二连组
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(2);
                for (int i = 0; i < first.length; i++) {
                    balls_firstLine.get(first[i]).setSelected(true);
                }
                ballView_one.invalidate();
                ballClick();
            }
            break;
//
//            case KLSF_SELTWO_DUPLEX://选二胆拖
//            {
//                ballClick();
//            }
//            break;
//
//            case KLSF_SELTHREE_DUPLEX://选三胆拖
//            {
//                ballClick();
//            }
//            break;
//            case KLSF_SELFOUR_DUPLEX://选四胆拖
//            {
//                ballClick();
//            }
//            break;
//            case KLSF_SELFIVE_DUPLEX://选五胆拖
//            {
//                ballClick();
//            }
//            break;
//            case KLSF_TWOGROUP_DUPLEX://二连组胆拖
//            {
//                ballClick();
//            }
//            break;
        }

    }

    @Override
    public String getHelpUrl() {
        // TODO Auto-generated method stub
        return HelpUrlConstants.Help_KLSF;
    }

    @Override
    public String getHelpTitle() {
        // TODO Auto-generated method stub
        return getString(R.string.help_klsf);
    }

    @Override
    public void onItem(int position) {
        clear();
        popupClickItem(position);
    }

    @Override
    public void popupShow() {
        topView.setJianTouRotate_shun();

    }

    @Override
    public void popupDismiss() {
        topView.setJianTouRotate_ni();

    }

    @Override
    public void ballClick() {
        // TODO Auto-generated method stub
        long zhushu = getZhushu();
        long money = zhushu * 2;

        bottomView.setMoRenText1(zhushu + "注 ");
        bottomView.setMoRenText2("共" + money + "米");
    }

    @Override
    public void ballClick(WeiZhi wz) {
        // TODO Auto-generated method stub
        WeiZhi w = wz;
        // TODO Auto-generated method stub
        int left = w.getLeft() - 5;
        int right = w.getRight() + 5;
        int top = (int) ((ball_linear.getY1() - w.getPointY() + w.getTop()) - (w.getBottom() - w
                .getTop()) - 10);
        int bottom = (int) (ball_linear.getY1() - w.getPointY() + w.getTop());
        Rect rect = new Rect(left, top, right, bottom);
        moveQiu.setRect(rect, w.getNum(), w.getType(), w.isShowMoveBall);
    }

    private int wanFaId;

    private long getZhushu() {
        return ZhuShuFactory.getZhuShu(wanFaId).betZhuShu(arr_infos);
    }

    @Override
    public void onBottomLeftClick() {
        // TODO Auto-generated method stub
        clear();
    }

    @Override
    public void onBottomRightClick() {
        // TODO Auto-generated method stub
        if (!touZhu()) {
            AppToast.getToast().show("请先选择一注再投注");
        }
    }

    @Override
    protected void addMissValue() {
        super.addMissValue();
        if (missInfo != null) {
            switch (popupId) {
                case 0:
                    ballView_one.setMissValues(missInfo.missValue("1012MV_S1").get(0));
                    break;
                case 1:
                    ballView_one.setMissValues(missInfo.missValue("1012MV_H1").get(0));
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                    ballView_one.setMissValues(missInfo.missValue("1012MV_RX").get(0));
                    ballView_two.setMissValues(missInfo.missValue("1012MV_RX").get(0));
                    break;

            }
            LogUtil.d("重新加载遗漏。。。");
        } else {
            LogUtil.d("清除遗漏。。。");
            ballView_one.setMissValues(new ArrayList<Integer>());
            ballView_two.setMissValues(new ArrayList<Integer>());
        }

    }

    @Override
    protected void net() {
        topView.startRightAnim();
        super.net();
    }
}
